import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutterprojectportal/page/home_page.dart';
import 'package:flutterprojectportal/route/page_route.dart';
import 'package:flutterprojectportal/support/route_manager.dart';

void main() {
  RouteManager.initRoute(allPageRout);

  runApp(AppHome(
    route: window.defaultRouteName, // 页面启动时的原始路由
  ));
}

class AppHome extends StatefulWidget {
  const AppHome({Key key, this.route}) : super(key: key);
  final String route;

  @override
  _AppHomeState createState() => _AppHomeState();
}

class _AppHomeState extends State<AppHome> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      initialRoute: "home_page",
      theme: ThemeData(
          primaryColor: Colors.blue,
          backgroundColor: Colors.blue,
          accentColor: Color(0xFF888888),
          textTheme: TextTheme(
              body1: TextStyle(color: Color(0xFF888888), fontSize: 15.0)),
          iconTheme: IconThemeData(color: Colors.white, size: 35.0)),
      onGenerateRoute: RouteManager.onGenerateRoute,
      onUnknownRoute: _onUnknownRoute,
    );
  }
}

// 自定义未找到的没有匹配页面时显示的
Route<dynamic> _onUnknownRoute(RouteSettings settings) {
  return MaterialPageRoute(
    settings: settings,
    builder: (BuildContext context) => Container(
      child: Text("未找到对应路由页面: ${settings.name}"),
    ),
  );
}
